package cn.pku.sirx.snad.uias.analyzer;

import org.springframework.util.Assert;

import cn.pku.sirx.snad.uias.analyzer.relationship.IRelationshipAnalyzer;
import cn.pku.sirx.snad.uias.util.AnalyzerUtils;
import cn.pku.sirx.util.MathUtils;

/**
 * @author WangXiao
 */
public class UserRelationshipAnalyzer implements IAnalyzer {

	public UserRelationshipAnalyzer() {
		weightVector = MathUtils.standardizeVector(weightVector);
	}

	@Override
	public double analyze(String fromUserId, String toUserId) {
		Assert.notNull(fromUserId);
		Assert.notNull(toUserId);

		double[] valueVector = new double[] {
				friendshipAnalyzer.analyze(fromUserId, toUserId),
				commonFriendsAnalyzer.analyze(fromUserId, toUserId) };
		return AnalyzerUtils.analyzeByWeight(weightVector, valueVector);
	}

	private double[] weightVector = { 10, 1 };

	private IRelationshipAnalyzer friendshipAnalyzer;
	private IRelationshipAnalyzer commonFriendsAnalyzer;

	public void setFriendshipAnalyzer(IRelationshipAnalyzer friendshipAnalyzer) {
		this.friendshipAnalyzer = friendshipAnalyzer;
	}

	public void setCommonFriendsAnalyzer(
			IRelationshipAnalyzer commonFriendsAnalyzer) {
		this.commonFriendsAnalyzer = commonFriendsAnalyzer;
	}

}
